<template>
  <div class="login_container">
    <div class="login_conten">
      <div class="login_title">登陆账号</div>
      <div class="login_title_two">虾米-严选商城欢迎您</div>

      <div class="login_form">
        <van-form @submit="onSubmit">
          <van-field
            v-model="username"
            name="用户名"
            placeholder="用户名"
            :rules="[{ required: true, message: '请填写用户名' }]"
          />
          <van-field
            v-model="password"
            type="password"
            name="密码"
            placeholder="密码"
            :rules="[{ required: true, message: '请填写密码' }]"
          />
          <div style="margin: 16px">
            <van-button round block type="info" native-type="submit">
              提交
            </van-button>
          </div>
        </van-form>
      </div>

      <div class="login_text">忘记密码</div>

      <div class="login_title_three" @click="gojoin">还没有注册？立即注册</div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      username: "",
      password: "",
    };
  },
  mounted() {},
  methods: {
    onSubmit() {
      this.$API
        .getlogin({
          mobile: this.username,
          pwd: this.password,
        })
        .then((res) => {
          console.log(res);
          if (res.data.data.token) {
              alert("登陆成功") 
              localStorage.setItem("token",res.data.data.token)
            this.$router.push("/");
            // if(localStorage.getItem('token')){
            //     alert("已登陆")
            //     return
            // }
          }
        });
    },
    gojoin(){
        this.$router.push("/join")
    }
  },
};
</script>

<style scoped>
.login_container {
  width: 90%;
  height: 13rem;
  border: 1px solid rgb(216, 214, 214);
  border-radius: 0.2rem;
  margin: 0 auto;
  margin-top: 0.5rem;
}
.login_conten {
  width: 90%;
  height: 100%;
  /* border: 1px solid #000; */
  margin: 0 auto;
}
.login_title {
  font-size: 0.6rem;
  margin-top: 0.5rem;
}
.login_title_two {
  margin-top: 0.3rem;
  font-size: 0.3rem;
  color: rgb(172, 169, 169);
}
.login_form {
  margin-top: 0.5rem;
}
.login_text {
  width: 100%;
  height: 1rem;
  /* background-color: cornflowerblue; */
  color: rgb(187, 182, 182);
  text-align: center;
  line-height: 1rem;
  font-size: 0.3rem;
}
.login_title_three {
  width: 100%;
  height: 1rem;
  /* background-color: darkblue; */
  text-align: center;
  line-height: 1rem;
  color: rgb(113, 165, 233);
}
</style>